home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Freeware / Miro 1.0 / Miro_Installer.exe / xulrunner / python / test / unicodetest.py < prev    next >
Encoding:
Python Source  |  2007-11-12  |  20.5 KB  |  408 lines

  1. import unittest
  2. from tempfile import mkstemp
  3. from time import sleep
  4. import time
  5. import types
  6.  
  7. import feed
  8. import item
  9. import database
  10. import feedparser
  11. import app
  12. import dialogs
  13. import framework
  14. import os
  15. import gtcache
  16. import gettext
  17. import resources
  18. import template
  19. import util
  20. from template_compiler import TemplateError
  21. import template_compiler
  22.  
  23. from test.framework import DemocracyTestCase
  24.  
  25. class UnicodeTestDelegate:
  26.     def __init__(self):
  27.         self.choice = None
  28.         self.numCalls = 0
  29.     def runDialog(self, dialog):
  30.         self.numCalls += 1
  31.         # print "rundialog called from %s" % dialog.title
  32.         dialog.choice = self.choice
  33.         # a bit of a hack to avoid using eventloop
  34.         dialog.callback(dialog)
  35.  
  36. class UnicodeFeedTestCase(framework.EventLoopTest):
  37.     def setUp(self):
  38.         super(UnicodeFeedTestCase, self).setUp()
  39.  
  40.     def isProperFeedParserDict(self, parsed, name="top"):
  41.         if isinstance(parsed, types.DictionaryType):
  42.             for (key, value) in parsed.items():
  43.                 self.isProperFeedParserDict(value, key)
  44.         elif (isinstance(parsed, types.ListType) or
  45.               isinstance(parsed, types.TupleType)):
  46.             for value in parsed:
  47.                 self.isProperFeedParserDict(value, name)
  48.         elif isinstance(parsed, types.StringType):
  49.             self.assert_(name in ["base","type","encoding","version","href","rel"])
  50.         elif isinstance(parsed, time.struct_time):
  51.             self.assert_(name in ["updated_parsed"])
  52.         elif isinstance(parsed, types.IntType):
  53.             self.assert_(name in ["bozo"])
  54.         else:
  55.             self.assert_((isinstance(parsed,types.UnicodeType) or
  56.                           isinstance(parsed,types.NoneType)))
  57.  
  58.     # Returns true iff value is a python unicode string containing
  59.     # only ascii characters
  60.     def isASCIIUnicode(self, value):
  61.         return ((type(value) == types.UnicodeType) and
  62.                 (value == value.encode('ascii')))
  63.  
  64.     def testValidUTF8Feed(self):
  65.         [handle, self.filename] = mkstemp(".xml")
  66.         handle =file(self.filename,"wb")
  67.         handle.write(u'<?xml version="1.0"?>\n<rss version="2.0">\n   <channel>\n <title>Chinese Numbers \u25cb\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d</title>\n      <description>Chinese Numbers \u25cb\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d</description>\n      <language>zh-zh</language>\n     <pubDate>Fri, 25 Aug 2006 17:39:21 GMT</pubDate>\n      <generator>Weblog Editor 2.0</generator>\n      <managingEditor>editor@example.com</managingEditor>\n      <webMaster>webmaster@example.com</webMaster>\n      <item>\n\n         <title>\u25cb\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d</title>\n     <link>http://participatoryculture.org/boguslink</link>\n         <description>\u25cb\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d</description>\n        <enclosure url="file://crap" length="0" type="video/mpeg"/>\n         <pubDate>Fri, 25 Aug 2006 17:39:21 GMT</pubDate>\n      </item>\n   </channel>\n</rss>'.encode('utf-8'))
  68.  
  69.         handle.close()
  70.  
  71.         myFeed = feed.Feed(u"file://"+self.filename)
  72.         self.forceFeedParserCallback(myFeed)
  73.  
  74.         self.isProperFeedParserDict(myFeed.parsed)
  75.  
  76.         # We need to explicitly check that the type is unicode because
  77.         # Python automatically converts bytes strings to unicode strings
  78.         # using the current system character set
  79.         self.assertEqual(type(myFeed.getTitle()), types.UnicodeType)
  80.         self.assertEqual(u"Chinese Numbers \u25cb\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d",myFeed.getTitle())
  81.  
  82.         # The description is the same, but surrounded by a <span>
  83.         self.assertEqual(type(myFeed.getDescription()), types.UnicodeType)
  84.         self.assertEqual(u"<span>Chinese Numbers \u25cb\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d</span>",myFeed.getDescription())
  85.  
  86.         items = database.defaultDatabase.filter(lambda x:x.__class__ == item.Item)
  87.         self.assertEqual(items.len(),1)
  88.         i = items[0]
  89.         self.assertEqual(type(i.getTitle()), types.UnicodeType)
  90.         self.assertEqual(u"\u25cb\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d",i.getTitle())
  91.  
  92.         self.assertEqual(type(i.getDescription()), types.UnicodeType)
  93.         self.assertEqual(u"<span>\u25cb\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d</span>",i.getDescription())
  94.  
  95.     def forceFeedParserCallback(self, myFeed):
  96.         # a hack to get the feed to update without eventloop
  97.         myFeed.feedparser_callback(feedparser.parse(myFeed.initialHTML))
  98.  
  99.     # This is a latin1 feed that claims to be UTF-8
  100.     def testInvalidLatin1Feed(self):
  101.         [handle, self.filename] = mkstemp(".xml")
  102.         handle = file(self.filename,"wb")
  103.         handle.write('<?xml version="1.0"?>\n<rss version="2.0">\n   <channel>\n      <title>H\xe4ppy Birthday</title>\n      <description>H\xe4ppy Birthday</description>\n <language>zh-zh</language>\n      <pubDate>Fri, 25 Aug 2006 17:39:21 GMT</pubDate>\n      <generator>Weblog Editor 2.0</generator>\n      <managingEditor>editor@example.com</managingEditor>\n      <webMaster>webmaster@example.com</webMaster>\n      <item>\n         <title>H\xe4ppy Birthday</title>\n         <link>http://participatoryculture.org/boguslink</link>\n         <description>H\xe4ppy Birthday</description>\n         <enclosure url="file://crap" length="0" type="video/mpeg"/>\n         <pubDate>Fri, 25 Aug 2006 17:39:21 GMT</pubDate>\n      </item>\n   </channel>\n</rss>')
  104.         handle.close()
  105.  
  106.         dialogs.delegate = UnicodeTestDelegate()
  107.         dialogs.delegate.choice = dialogs.BUTTON_YES
  108.  
  109.         myFeed = feed.Feed(u"file://"+self.filename)
  110.  
  111.         myFeed.update()
  112.         self.processThreads()
  113.         self.processIdles()
  114.         self.assertEqual(len(myFeed.items), 1)
  115.         myItem = myFeed.items[0]
  116.         self.assertEqual(len(myItem.getTitle()), 14)
  117.         self.assertEqual(myItem.getTitle(), u"H\xe4ppy Birthday")
  118.  
  119.     # This is latin1 HTML that claims to be Latin 1
  120.     def testLatin1HTML(self):
  121.         [handle, self.filename] = mkstemp(".html")
  122.         handle =file(self.filename,"wb")
  123.         handle.write('<?xml version="1.0" encoding="iso-8859-1"?>\n<html>\n   <head>\n       <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />\n  <title>H\xe4ppy Birthday</title>\n   </head>\n   <body>\n   <a href="http://www.wccatv.com/files/video/hbml.mov">H\xe4ppy Birthday</a>\n   </body>\n</html>')
  124.         handle.close()
  125.  
  126.         dialogs.delegate = UnicodeTestDelegate()
  127.         dialogs.delegate.choice = dialogs.BUTTON_YES
  128.  
  129.         myFeed = feed.Feed(u"file://"+self.filename)
  130.         
  131.         self.assertEqual(dialogs.delegate.numCalls, 1)
  132.         myFeed.update()
  133.         self.assertEqual(len(myFeed.items), 1)
  134.         myItem = myFeed.items[0]
  135.         self.assertEqual(len(myItem.getTitle()), 14)
  136.         self.assertEqual(myItem.getTitle(), u"H\xe4ppy Birthday")
  137.  
  138.     # This is latin1 HTML that claims to be UTF-8
  139.     def testInvalidLatin1HTML(self):
  140.         [handle, self.filename] = mkstemp(".html")
  141.         handle =file(self.filename,"wb")
  142.         handle.write('<?xml version="1.0" encoding="utf-8"?>\n<html>\n   <head>\n       <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\n      <title>H\xe4ppy Birthday</title>\n   </head>\n   <body>\n   <a href="http://www.wccatv.com/files/video/hbml.mov">H\xe4ppy Birthday</a>\n   </body>\n</html>')
  143.         handle.close()
  144.  
  145.         dialogs.delegate = UnicodeTestDelegate()
  146.         dialogs.delegate.choice = dialogs.BUTTON_YES
  147.  
  148.         myFeed = feed.Feed(u"file://"+self.filename)
  149.         
  150.         self.assertEqual(dialogs.delegate.numCalls,1)
  151.         myFeed.update()
  152.         self.assertEqual(len(myFeed.items),1)
  153.         myItem = myFeed.items[0]
  154.         self.assertEqual(len(myItem.getTitle()),14)
  155.         self.assertEqual(myItem.getTitle(), u"H\xe4ppy Birthday")
  156.  
  157.     # This is utf-8 HTML that claims to be utf-8
  158.     def testUTF8HTML(self):
  159.         [handle, self.filename] = mkstemp(".html")
  160.         handle =file(self.filename,"wb")
  161.         handle.write('<?xml version="1.0" encoding="utf-8"?>\n<html>\n   <head>\n       <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\n      <title>H\xc3\xa4ppy Birthday</title>\n   </head>\n   <body>\n   <a href="http://www.wccatv.com/files/video/hbml.mov">H\xc3\xa4ppy Birthday</a>\n   </body>\n</html>')
  162.         handle.close()
  163.  
  164.         dialogs.delegate = UnicodeTestDelegate()
  165.         dialogs.delegate.choice = dialogs.BUTTON_YES
  166.  
  167.         myFeed = feed.Feed(u"file://"+self.filename)
  168.         
  169.         self.assertEqual(dialogs.delegate.numCalls,1)
  170.         myFeed.update()
  171.         self.assertEqual(len(myFeed.items),1)
  172.         myItem = myFeed.items[0]
  173.         self.assertEqual(len(myItem.getTitle()),14)
  174.         self.assertEqual(myItem.getTitle(), u"H\xe4ppy Birthday")
  175.  
  176.     def testUTF8HTMLLinks(self):
  177.         [handle, self.filename] = mkstemp(".html")
  178.         handle =file(self.filename,"wb")
  179.         handle.write('<?xml version="1.0" encoding="utf-8"?>\n<html>\n   <head>\n       <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\n      <title>H\xc3\xa4ppy Birthday</title>\n   </head>\n   <body>\n   <a href="http://www.wccatv.com/files/video/H\xc3\xa4ppy.mov">H\xc3\xa4ppy Birthday</a>\n   </body>\n</html>')
  180.         handle.close()
  181.  
  182.         dialogs.delegate = UnicodeTestDelegate()
  183.         dialogs.delegate.choice = dialogs.BUTTON_YES
  184.  
  185.         myFeed = feed.Feed(u"file://"+self.filename)
  186.         
  187.         self.assertEqual(dialogs.delegate.numCalls,1)
  188.         myFeed.update()
  189.         # Either the item isn't added or it's added with an ascii URL
  190.         if len(myFeed.items) > 0:
  191.             self.assertEqual(len(myFeed.items),1)
  192.             myItem = myFeed.items[0]
  193.             myURL = myItem.getURL()
  194.             self.assertEqual(str(myURL),myURL)
  195.  
  196.     def testLatin1HTMLLinks(self):
  197.         [handle, self.filename] = mkstemp(".html")
  198.         handle =file(self.filename,"wb")
  199.         handle.write('<?xml version="1.0" encoding="iso-8859-1"?>\n<html>\n   <head>\n <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />\n   <title>H\xe4ppy Birthday</title>\n   </head>\n   <body>\n   <a href="http://www.wccatv.com/files/video/H\xe4ppy.mov">H\xe4ppy Birthday</a>\n   </body>\n</html>')
  200.         handle.close()
  201.  
  202.         dialogs.delegate = UnicodeTestDelegate()
  203.         dialogs.delegate.choice = dialogs.BUTTON_YES
  204.  
  205.         myFeed = feed.Feed(u"file://"+self.filename)
  206.         
  207.         self.assertEqual(dialogs.delegate.numCalls,1)
  208.         myFeed.update()
  209.         # Either the item isn't added or it's added with an ascii URL
  210.         if len(myFeed.items) > 0:
  211.             self.assertEqual(len(myFeed.items),1)
  212.             myItem = myFeed.items[0]
  213.             myURL = myItem.getURL()
  214.             self.assertEqual(str(myURL),myURL)
  215.  
  216.     def testInvalidLatin1HTMLLinks(self):
  217.         [handle, self.filename] = mkstemp(".html")
  218.         handle =file(self.filename,"wb")
  219.         handle.write('<?xml version="1.0" encoding="iso-8859-1"?>\n<html>\n   <head>\n       <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />\n      <title>H\xc3\xa4ppy Birthday</title>\n   </head>\n   <body>\n   <a href="http://www.wccatv.com/files/video/H\xc3\xa4ppy.mov">H\xc3\xa4ppy Birthday</a>\n   </body>\n</html>')
  220.         handle.close()
  221.  
  222.         dialogs.delegate = UnicodeTestDelegate()
  223.         dialogs.delegate.choice = dialogs.BUTTON_YES
  224.  
  225.         myFeed = feed.Feed(u"file://"+self.filename)
  226.         
  227.         self.assertEqual(dialogs.delegate.numCalls,1)
  228.         myFeed.update()
  229.         # Either the item isn't added or it's added with an ascii URL
  230.         if len(myFeed.items) > 0:
  231.             self.assertEqual(len(myFeed.items),1)
  232.             myItem = myFeed.items[0]
  233.             myURL = myItem.getURL()
  234.             self.assertEqual(str(myURL),myURL)
  235.  
  236.     def testUTF8HTMLThumbs(self):
  237.         [handle, self.filename] = mkstemp(".html")
  238.         handle =file(self.filename,"wb")
  239.         handle.write('<?xml version="1.0" encoding="utf-8"?>\n<html>\n   <head>\n <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\n      <title>H\xc3\xa4ppy Birthday</title>\n   </head>\n   <body>\n   <a href="http://www.wccatv.com/files/video/hbml.mov"><img src="http://www.wccatv.com/files/video/H\xc3\xa4ppy.png"/>H\xc3\xa4ppy Birthday</a>\n   </body>\n</html>')
  240.         handle.close()
  241.  
  242.         dialogs.delegate = UnicodeTestDelegate()
  243.         dialogs.delegate.choice = dialogs.BUTTON_YES
  244.  
  245.         myFeed = feed.Feed(u"file://"+self.filename)
  246.         
  247.         self.assertEqual(dialogs.delegate.numCalls,1)
  248.         myFeed.update()
  249.  
  250.         self.assertEqual(len(myFeed.items),1)
  251.         myItem = myFeed.items[0]
  252.         myURL = myItem.getURL()
  253.         self.assertEqual(str(myURL),myURL)
  254.  
  255.         thumb = myItem.getThumbnailURL()
  256.         if thumb is not None:
  257.             self.assertEqual(str(thumb),thumb)
  258.  
  259.     def testLatin1HTMLThumbs(self):
  260.         [handle, self.filename] = mkstemp(".html")
  261.         handle =file(self.filename,"wb")
  262.         handle.write('<?xml version="1.0" encoding="iso-8859-1"?>\n<html>\n   <head>\n  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />\n    <title>H\xe4ppy Birthday</title>\n   </head>\n   <body>\n   <a href="http://www.wccatv.com/files/video/hbml.mov"><img src="http://www.wccatv.com/files/video/H\xe4ppy.png"/>H\xe4ppy Birthday</a>\n   </body>\n</html>')
  263.         handle.close()
  264.  
  265.         dialogs.delegate = UnicodeTestDelegate()
  266.         dialogs.delegate.choice = dialogs.BUTTON_YES
  267.  
  268.         myFeed = feed.Feed(u"file://"+self.filename)
  269.         
  270.         self.assertEqual(dialogs.delegate.numCalls,1)
  271.         myFeed.update()
  272.  
  273.         self.assertEqual(len(myFeed.items),1)
  274.         myItem = myFeed.items[0]
  275.         myURL = myItem.getURL()
  276.         self.assertEqual(str(myURL),myURL)
  277.  
  278.         thumb = myItem.getThumbnailURL()
  279.         if thumb is not None:
  280.             self.assertEqual(str(thumb),thumb)
  281.  
  282.     def testInvalidLatin1HTMLThumbs(self):
  283.         [handle, self.filename] = mkstemp(".html")
  284.         handle =file(self.filename,"wb")
  285.         handle.write('<?xml version="1.0" encoding="iso-8859-1"?>\n<html>\n   <head>\n       <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />\n <title>H\xc3\xa4ppy Birthday</title>\n   </head>\n   <body>\n   <a href="http://www.wccatv.com/files/video/hbml.mov"><img src="http://www.wccatv.com/files/video/H\xc3\xa4ppy.png"/>H\xc3\xa4ppy Birthday</a>\n   </body>\n</html>')
  286.         handle.close()
  287.  
  288.         dialogs.delegate = UnicodeTestDelegate()
  289.         dialogs.delegate.choice = dialogs.BUTTON_YES
  290.  
  291.         myFeed = feed.Feed(u"file://"+self.filename)
  292.         
  293.         self.assertEqual(dialogs.delegate.numCalls,1)
  294.         myFeed.update()
  295.  
  296.         self.assertEqual(len(myFeed.items),1)
  297.         myItem = myFeed.items[0]
  298.         myURL = myItem.getURL()
  299.         self.assertEqual(str(myURL),myURL)
  300.  
  301.         thumb = myItem.getThumbnailURL()
  302.         if thumb is not None:
  303.             self.assertEqual(str(thumb),thumb)
  304.  
  305.     def testDemocracyNowBug(self):
  306.         url = resources.url("testdata/democracy-now-unicode-bug.xml")
  307.         myFeed = feed.Feed(url)
  308.         self.forceFeedParserCallback(myFeed)
  309.         for item in myFeed.items:
  310.             u'booya' in item.getTitle().lower()
  311.  
  312.     def testGetText(self):
  313.         # FIXME this only works on GTK platforms. See #3831
  314.         oldLang = None
  315.         try:
  316.             oldLang = os.environ["LANGUAGE"]
  317.         except:
  318.             pass
  319.         os.environ["LANGUAGE"] = "fr"
  320.         gtcache._gtcache = {}
  321.  
  322.         gettext.bindtextdomain("miro",resources.path("../../locale"))
  323.         gettext.textdomain("miro")
  324.         gettext.bind_textdomain_codeset("miro","UTF-8")
  325.         self.assertEqual(gtcache.gettext("Settings"),u'R\xe9glages')
  326.         if oldLang is None:
  327.             del os.environ["LANGUAGE"]
  328.         else:
  329.             os.environ["LANGUAGE"] = oldLang
  330.  
  331.     def testTemplates(self):
  332.         # This tests that templates output valid UTF-8
  333.         
  334.         # FIXME this only works on GTK platforms. See #3831
  335.         oldLang = None
  336.         try:
  337.             oldLang = os.environ["LANGUAGE"]
  338.         except:
  339.             pass
  340.         os.environ["LANGUAGE"] = "fr"
  341.         gtcache._gtcache = {}
  342.  
  343.         gettext.bindtextdomain("miro",resources.path("../../locale"))
  344.         gettext.textdomain("miro")
  345.         gettext.bind_textdomain_codeset("miro","UTF-8")
  346.  
  347.         out = template.fillStaticTemplate("unittest/simpleunicode", "gtk-x11", "noCookie")
  348.         self.assert_(type(out)==types.UnicodeType)
  349.         # We shouldn't find utf-8 versions of this text
  350.         self.assert_(out.find(u'<h1>H\xc3\xa4ppy Birthday</h1>') == -1)
  351.         self.assert_(out.find(u'<p>R\xc3\xa9glages</p>') == -1)
  352.  
  353.         # We should find the unicode string
  354.         self.assert_(out.find(u"<h1>H\xe4ppy Birthday</h1>") != -1)
  355.         self.assert_(out.find(u"<p>R\xe9glages</p>") != -1)
  356.         if oldLang is None:
  357.             del os.environ["LANGUAGE"]
  358.         else:
  359.             os.environ["LANGUAGE"] = oldLang
  360.  
  361. class TemplateCompilerTest(framework.DemocracyTestCase):
  362.     def testNonUnicode(self):
  363.         # genRepeatText
  364.         self.assertRaises(util.DemocracyUnicodeError,
  365.                           lambda : template_compiler.genRepeatText("out","123","    ","boo"))
  366.         self.assertRaises(util.DemocracyUnicodeError,
  367.                           lambda : template_compiler.genRepeatText("out","123","    ","Chinese Numbers \x25cb\x4e00\x4e8c\x4e09\x56db\x4e94\x516d\x4e03\x516b\x4e5d"))
  368.         self.assertEqual(u"    out.write(u'Chinese Numbers \\u25cb\\u4e00\\u4e8c\\u4e09\\u56db\\u4e94\\u516d\\u4e03\\u516b\\u4e5d')\n",
  369.                          template_compiler.genRepeatText("out","123","    ",u"Chinese Numbers \u25cb\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d"))
  370.  
  371.  
  372.         # genRepeatTranslate
  373.         self.assertRaises(util.DemocracyUnicodeError,
  374.                           lambda : template_compiler.genRepeatTranslate("out","123","    ",("boo",{})))
  375.         self.assertRaises(util.DemocracyUnicodeError,
  376.                           lambda : template_compiler.genRepeatTranslate("out","123","    ",("Chinese Numbers \x25cb\x4e00\x4e8c\x4e09\x56db\x4e94\x516d\x4e03\x516b\x4e5d",{})))
  377.  
  378.  
  379.         # genRepeatTextHide
  380.         self.assertRaises(util.DemocracyUnicodeError,
  381.                           lambda : template_compiler.genRepeatTextHide("out","123","    ",(False,"boo")))
  382.         self.assertRaises(util.DemocracyUnicodeError,
  383.                           lambda : template_compiler.genRepeatTextHide("out","123","    ",(False, "Chinese Numbers \x25cb\x4e00\x4e8c\x4e09\x56db\x4e94\x516d\x4e03\x516b\x4e5d")))
  384.         self.assertRaises(util.DemocracyUnicodeError,
  385.                           lambda : template_compiler.genRepeatTextHide("out","123","    ",(True,"boo")))
  386.         self.assertRaises(util.DemocracyUnicodeError,
  387.                           lambda : template_compiler.genRepeatTextHide("out","123","    ",(True, "Chinese Numbers \x25cb\x4e00\x4e8c\x4e09\x56db\x4e94\x516d\x4e03\x516b\x4e5d")))
  388.  
  389.         self.assertEqual(u"    if not (True):\n        out.write(u'Chinese Numbers \\u25cb\\u4e00\\u4e8c\\u4e09\\u56db\\u4e94\\u516d\\u4e03\\u516b\\u4e5d')\n",
  390.                          template_compiler.genRepeatTextHide("out","123","    ",(True, u"Chinese Numbers \u25cb\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d")))
  391.  
  392.         # genHideSection
  393.         self.assertRaises(util.DemocracyUnicodeError,
  394.                           lambda : template_compiler.genHideSection("out","123","    ",(False,[(lambda a,b,c,d: "boo","ignored")])))
  395.         self.assertRaises(util.DemocracyUnicodeError,
  396.                           lambda : template_compiler.genHideSection("out","123","    ",(False,[(lambda a,b,c,d: "Chinese Numbers \x25cb\x4e00\x4e8c\x4e09\x56db\x4e94\x516d\x4e03\x516b\x4e5d","ignored")])))
  397.         self.assertEqual(u'    if not (False):\nChinese Numbers \u25cb\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d',
  398.                           template_compiler.genHideSection("out","123","    ",(False,[(lambda a,b,c,d: u"Chinese Numbers \u25cb\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d","ignored")])))
  399.  
  400.         # genQuoteAndFillAttr
  401.         self.assertRaises(util.DemocracyUnicodeError,
  402.                           lambda:template_compiler.genQuoteAndFillAttr("out","123","    ","boo"))
  403.         self.assertRaises(util.DemocracyUnicodeError,
  404.                           lambda:template_compiler.genQuoteAndFillAttr("out","123","    ","Chinese Numbers \x25cb\x4e00\x4e8c\x4e09\x56db\x4e94\x516d\x4e03\x516b\x4e5d"))
  405.         self.assertEqual(u"    out.write(quoteAndFillAttr(u'Chinese Numbers \\u25cb\\u4e00\\u4e8c\\u4e09\\u56db\\u4e94\\u516d\\u4e03\\u516b\\u4e5d',locals()))\n",
  406.                          template_compiler.genQuoteAndFillAttr("out","123","    ",u"Chinese Numbers \u25cb\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d"))
  407.  
  408.